package com.mxgraph.generatorfunction;

import com.mxgraph.view.mxCellState;

/**
 * The type Mx generator random int function.
 *
 * @author Mate  A generator random cost function It will generate random integer edge weights in the range of (<b>minWeight</b>, <b>maxWeight</b>) and rounds the values to <b>roundToDecimals</b>
 */
public class mxGeneratorRandomIntFunction extends mxGeneratorFunction {
    private double maxWeight = 10;

    private double minWeight = 0;

    /**
     * Instantiates a new Mx generator random int function.
     *
     * @param minWeight the min weight
     * @param maxWeight the max weight
     */
    public mxGeneratorRandomIntFunction(double minWeight, double maxWeight) {
        setWeightRange(minWeight, maxWeight);
    }

    ;

    public double getCost(mxCellState state) {
        //assumed future parameters
        //		mxGraph graph = state.getView().getGraph();
        //		Object cell = state.getCell();

        if (minWeight == maxWeight) {
            return minWeight;
        }

        double currValue = minWeight + Math.round((Math.random() * (maxWeight - minWeight)));
        return currValue;
    }

    ;

    /**
     * Gets max weight.
     *
     * @return the max weight
     */
    public double getMaxWeight() {
        return maxWeight;
    }

    ;

    /**
     * Sets weight range.
     *
     * @param minWeight the min weight
     * @param maxWeight the max weight
     */
    public void setWeightRange(double minWeight, double maxWeight) {
        this.maxWeight = Math.round(Math.max(minWeight, maxWeight));
        this.minWeight = Math.round(Math.min(minWeight, maxWeight));
    }

    ;

    /**
     * Gets min weight.
     *
     * @return the min weight
     */
    public double getMinWeight() {
        return minWeight;
    }

    ;
};
